fix(s02): handle Anthropic SDK content blocks in normalize_messages#207
fix(s02): handle Anthropic SDK content blocks in normalize_messages#207wadeKeith wants to merge 3 commits into
Conversation
|
@wadeKeith is attempting to deploy a commit to the crazyboym's projects Team on Vercel. A member of the Team first needs to authorize it. |
36897b1 to
d882d01
Compare
faca156 to
bab0e67
Compare
|
The Vercel deploy CI failures appear to be an organization-level permission issue — the deploy is attempting to target the |
|
Quick update on the CI situation:
The actual Python + web build code changes are clean and tested. |
The original normalize_messages() used isinstance(block, dict) to filter content blocks, but Anthropic SDK returns pydantic model objects (e.g. ToolUseBlock, TextBlock), not plain dicts. This caused tool_use blocks to be silently dropped, leading to 'tool_result tool_use_id not found' errors (400) on the next API call. Added _block_to_dict() helper that converts SDK objects via model_dump() or vars() fallback, and removed the isinstance(block, dict) guard so all content blocks are properly serialized.
bab0e67 to
3774147
Compare
|
Rebased to resolve merge conflicts. The Vercel deployment failures are expected for fork PRs - not a code issue. Ready for review. |
Problem
s02_tool_use.pycrashes with:Root Cause
normalize_messages()usesisinstance(block, dict)to filter content blocks, but the Anthropic SDK storesresponse.contentas pydantic model objects (ToolUseBlock,TextBlock), not plain dicts. This silently drops all tool_use blocks during normalization, so the subsequenttool_resultreferences an id the API never saw.Fix
Added a
_block_to_dict()helper that converts SDK objects to plain dicts viamodel_dump()(withvars()fallback), and removed theisinstance(block, dict)guard so all content blocks are properly serialized.Changes
agents/s02_tool_use.py: +13 / -3 lines_block_to_dict(block)functionnormalize_messages()to use itTested locally — the agent loop now completes tool calls without errors.